package com.example.musicaiap.data.database

import androidx.room.Embedded
import androidx.room.Junction
import androidx.room.Relation
import com.example.musicaiap.domain.model.Playlist
import com.example.musicaiap.domain.model.Song

/**
 * 播放列表与歌曲的关系类
 * 用于Room数据库查询播放列表包含的所有歌曲
 */
data class PlaylistWithSongs(
    @Embedded val playlist: PlaylistEntity,
    
    @Relation(
        parentColumn = "id",
        entityColumn = "id",
        associateBy = Junction(
            value = PlaylistSongCrossRef::class,
            parentColumn = "playlistId",
            entityColumn = "songId"
        )
    )
    val songs: List<SongEntity>
) {
    /**
     * 转换为领域模型
     */
    fun toDomainModel(): Pair<Playlist, List<Song>> {
        val domainPlaylist = playlist.toDomainModel(songs.size)
        val domainSongs = songs.map { it.toDomainModel() }
        return Pair(domainPlaylist, domainSongs)
    }
} 